package cn.edu.nit.sys.controller;

import cn.edu.nit.sys.entity.Room;
import cn.edu.nit.sys.service.RoomService;
import cn.edu.nit.sys.utils.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author xiaobai
 * @Date 2022/11/19 20:15
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/room")
public class RoomController {

    @Autowired
    private RoomService roomService;

    @GetMapping
    public R getRoomList(String siftName, Page<Room> page) {
        return roomService.getRoomList(siftName, page);
    }

    @PostMapping
    public R addRoom(@RequestBody Room room) {
        return roomService.addRoom(room);
    }

    @PutMapping
    public R updateRoom(@RequestBody Room room) {
        return roomService.updateById(room) ? R.ok("修改成功") : R.error("修改失败");
    }

    @DeleteMapping("/{id}")
    public R delRoom(@PathVariable("id")Long id) {
        return roomService.removeById(id) ? R.ok("删除成功") : R.error("删除失败");
    }
}
